package com.shengyuan.manage_os.old.ying.erpm;

import org.json.JSONException;

import com.shengyuan.manage_os.R;
import com.shengyuan.manage_os.old.ying.erpm.controls.PictureButton;
import com.shengyuan.manage_os.old.ying.erpm.tasks.Submit_System_Setting_Data_Task;
import com.shengyuan.manage_os.old.ying.erpm.util.Utility;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class Actual_Form_PiZhongLiang extends BaseActivity {

	protected EditText editText_zongzhongliang, editText_pizhongliang;
	

	@Override
	public void onClick(View view) {
		super.onClick(view);
	}
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.actual_form_pizhongliang);
		InitControls();
	}

	protected void onCreate(Bundle savedInstanceState, boolean b) {
		super.onCreate(savedInstanceState);
	}
	
	@Override
	protected void onResume() {
		editText_pizhongliang.postInvalidate();
		PictureButton_bengshang.postInvalidate();
		PictureButton_bengma.postInvalidate();
		if (PictureButton_bengdan!=null) {
			PictureButton_bengdan.postInvalidate();
		}
		//
		super.onResume();
	}

	@Override
	protected void SaveJsonData() {
		try {
			IsJson1 = true;
			JsonMyID();
			getCar();
			
			//getZhuangdi();
			getXiedi();
			getTask();
			getCaiLiao();
			
			getZhongLiang();
			
			getGPS();
			getCurrentUser();		
			getMemo();
			JsonPicture();
			JsonPicture_Ext();
		}catch (Exception e) {
		}
	}


	
	protected void getZhongLiang() throws JSONException {
		if (editText_pizhongliang!=null) {
			mJson.put( getString(R.string.title_actual_form_editText_pizhongliang), 
					editText_pizhongliang.getText().toString());
		}
		//价格保存
		if (Submit_System_Setting_Data_Task.mID>=0 && editText_zongzhongliang!=null && editText_pizhongliang!=null) {
			Double mm = Double.parseDouble(editText_zongzhongliang.getText().toString()) -  Double.parseDouble(editText_pizhongliang.getText().toString()) ;
			String YuSuanJiaGe = Submit_System_Setting_Data_Task.J_GONGCHENGMINGCHENG_GC.getJSONObject(Submit_System_Setting_Data_Task.mID).getString("YuSuanJiaGe");
			int pmm = (int)(mm * Double.parseDouble(YuSuanJiaGe));
			mJson.put( getString(R.string.title_actual_form_yusuanjiage),  pmm);
			mJson.put( getString(R.string.title_actual_form_jiage),  YuSuanJiaGe);
		}
		
	}
	
	protected void JsonPicture_Ext() throws JSONException {
		if (PictureButton_bengshang!=null) {
			mJson.put( PictureButton_bengshang.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengshang.mFileName);
		}
		if (PictureButton_bengma!=null) {
			mJson.put( PictureButton_bengma.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengma.mFileName);
		}
		if (PictureButton_bengdan!=null) {
			mJson.put( PictureButton_bengdan.FIELD+getString(R.string.title_actual_form_PictureButton), PictureButton_bengdan.mFileName);
		}
	}	
	@Override
	protected void SaveSelfPic(String sPath) {
		try {
			CopyPicDest(PictureButton_Car, sPath);
//			CopyPicDest(PictureButton_Chexing, sPath);
			CopyPicDest(PictureButton_CaiLiao, sPath);
			CopyPicDest(PictureButton_bengshang, sPath);
			CopyPicDest(PictureButton_bengma, sPath);
//			CopyPicDest(PictureButton_bengdan, sPath);
		} catch (Exception e) {
			Utility.MessageBox(this,e.getMessage());
		}
	}

	@Override
	public void Back() {
		super.Back();
	}

	@Override
	public void InitControls() {
		super.InitControls();

		System.out.println("##########@@@@@@@@@==="+Submit_System_Setting_Data_Task.T_CHEXINGHAO+Submit_System_Setting_Data_Task.T_ZONGLIANG+Submit_System_Setting_Data_Task.T_CAILIAO);
		editText_zongzhongliang = (EditText) findViewById(R.id.editText_zongzhongliang);
		editText_chexing.setText(Submit_System_Setting_Data_Task.T_CHEXINGHAO);
		editText_zongzhongliang.setText(Submit_System_Setting_Data_Task.T_ZONGLIANG);
		editText_cailiao.setText(Submit_System_Setting_Data_Task.T_CAILIAO);
		editText_gongyingshang.setText(Submit_System_Setting_Data_Task.T_SHANGJIA);
		editText_pizhongliang =(EditText) findViewById(R.id.editText_pizhongliang);
	}
	
	@Override
	public Boolean IsPassed() {
		if (super.IsPassed()) {
			if(!CheckEditNumber(editText_pizhongliang))
				return false;
			if (!PictureButton_Car.IsExist()) {
				Utility.MessageBox(this, PictureButton_Car.FIELD );
				return false;
			}
//			if (!PictureButton_Chexing.IsExist()) {
//				Utility.MessageBox( PictureButton_Chexing.FIELD );
//				return false;
//			}		
//			if (!PictureButton_CaiLiao.IsExist()) {
//				Utility.MessageBox( PictureButton_CaiLiao.FIELD );
//				return false;
//			}
			if (!PictureButton_bengshang.IsExist()) {
				Utility.MessageBox(this, PictureButton_bengshang.FIELD );
				return false;
			}
			if (!PictureButton_bengma.IsExist()) {
				Utility.MessageBox(this, PictureButton_bengma.FIELD );
				return false;
			}
			if (PictureButton_bengdan!=null && !PictureButton_bengdan.IsExist()) {
				Utility.MessageBox(this, PictureButton_bengdan.FIELD );
				return false;
			}			
			return true;
		}else {
			return false;
		}
	}
}
